package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.HealthDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.service.HealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = HealthService.class)
@Transactional
public class HealthServiceImpl implements HealthService {

    @Autowired
    private HealthDao healthDao;


    int i=0;



    //体检信息录入分页查询
    @Override
    public PageResult findReportPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();//查询条件
        //完成分页查询，基于mybatis框架提供的分页助手插件完成
        PageHelper.startPage(currentPage,pageSize);
        //select * from t_checkitem limit 0,10
        Page<Map> page = healthDao.selectReportPage(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }


    //体检信息查询分页
    @Override
    public PageResult findQueryPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();//查询条件
        //完成分页查询，基于mybatis框架提供的分页助手插件完成
        PageHelper.startPage(currentPage,pageSize);
        //select * from t_checkitem limit 0,10
        Page<Map> page = healthDao.selectQueryPage(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public List<Map<String, Object>> findById(Integer id) {
        i = 0;
        List<Map<String,Object>> list=healthDao.findCheckGroupIdBymealId(id);
        return list;
    }

    @Override
    public void editValue(List<Map> list) {
        Integer orderid=0;
        for (Map map : list) {
            healthDao.edit(map);
        }

        for (Map map : list) {
             orderid = (Integer) map.get("orderid");
        }

        int emptyValue = healthDao.findEmptyValue(orderid);

        if(emptyValue==0){
            healthDao.editStatus(orderid);
        }
    }
}
